/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * zEditServiceList.java
 *
 * Created on Oct 31, 2011, 6:44:27 PM
 */
package introsemp;
import java.sql.*;
import javax.swing.table.*;
import java.util.*;
import java.io.*;
/**
 *
 * @author G
 */
public class Form_Income extends javax.swing.JFrame {

    /** Creates new form zEditServiceList */
    Form_MainMenu menu;
    DefaultTableModel terminaltable;
    DefaultTableModel servicetable;
    float terminalprice=0;
    float serviceprice=0;
    public Form_Income(Form_MainMenu menuGet) {
        initComponents();
        menu=menuGet;
        this.setSize(800,720);
        DailyPanel.setSize(750,710);
        terminaltable=(DefaultTableModel)TerminalRentalTable.getModel();
        servicetable=(DefaultTableModel)ServiceTable.getModel();
        Calendar cal = Calendar.getInstance();
        int day = cal.get(Calendar.DATE);
        int month = cal.get(Calendar.MONTH) + 1;
        int year = cal.get(Calendar.YEAR);
        DaySpinner.setValue(day);
        jTextField3.setText(Integer.toString(year));
        MonthCombo.setSelectedIndex(month-1);
         try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM terminalrental");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String num=allTerminals.getString("RentalType");
           int TerminalNum=allTerminals.getInt("TerminalNumber");
           String start=allTerminals.getString("StartTime");
           String end=allTerminals.getString("EndTime");
           String duration=allTerminals.getString("Duration");
           float price=allTerminals.getFloat("TotalPrice");
           terminaltable.addRow(new Object[]{num,TerminalNum,start,end,duration,price});
           terminalprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
          try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM customer");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String name=allTerminals.getString("CustomerName");
           String serviceName=allTerminals.getString("ServiceName");
           float price=allTerminals.getFloat("ServiceTotal");
           servicetable.addRow(new Object[]{name,serviceName,price});
          serviceprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
         TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ViewIncomeLabel = new javax.swing.JLabel();
        Separator1 = new javax.swing.JSeparator();
        DailyButton = new javax.swing.JButton();
        WeeklyButton = new javax.swing.JButton();
        MonthlyButton = new javax.swing.JButton();
        YearlyButton = new javax.swing.JButton();
        Separator2 = new javax.swing.JSeparator();
        DailyPanel = new javax.swing.JPanel();
        Daily_Date = new javax.swing.JLabel();
        Daily_Day = new javax.swing.JLabel();
        DaySpinner = new javax.swing.JSpinner();
        Daily_Month = new javax.swing.JLabel();
        MonthCombo = new javax.swing.JComboBox();
        Daily_Year = new javax.swing.JLabel();
        Daily_TerminalRentals = new javax.swing.JLabel();
        Daily_TerminalRentalPannel = new javax.swing.JScrollPane();
        TerminalRentalTable = new javax.swing.JTable();
        Daily_OtherServices = new javax.swing.JLabel();
        Daily_TerminalTotal = new javax.swing.JLabel();
        TerminalTotalText = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField3 = new javax.swing.JTextField();
        jScrollPane1 = new javax.swing.JScrollPane();
        ServiceTable = new javax.swing.JTable();
        ServiceTotalText = new javax.swing.JTextField();
        TotalText = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(980, 90));
        setResizable(false);

        ViewIncomeLabel.setFont(new java.awt.Font("Tahoma", 1, 18));
        ViewIncomeLabel.setText("View Income");

        DailyButton.setText("Daily");
        DailyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DailyButtonActionPerformed(evt);
            }
        });

        WeeklyButton.setText("Weekly");
        WeeklyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                WeeklyButtonActionPerformed(evt);
            }
        });

        MonthlyButton.setText("Monthly");
        MonthlyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                MonthlyButtonActionPerformed(evt);
            }
        });

        YearlyButton.setText("Yearly");
        YearlyButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                YearlyButtonActionPerformed(evt);
            }
        });

        Daily_Date.setFont(new java.awt.Font("sansserif", 1, 14));
        Daily_Date.setText("Date");

        Daily_Day.setText("Day:");

        DaySpinner.setModel(new javax.swing.SpinnerNumberModel(1, 1, 31, 1));

        Daily_Month.setText("Month:");

        MonthCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }));

        Daily_Year.setText("Year:");

        Daily_TerminalRentals.setFont(new java.awt.Font("sansserif", 1, 14));
        Daily_TerminalRentals.setText("Terminal Rentals");

        TerminalRentalTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Rental Type", "Terminal #", "Start Time", "End Time", "Total Time", "Amount"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.Object.class, java.lang.Integer.class, java.lang.Object.class, java.lang.Object.class, java.lang.Object.class, java.lang.Float.class
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }
        });
        Daily_TerminalRentalPannel.setViewportView(TerminalRentalTable);

        Daily_OtherServices.setFont(new java.awt.Font("sansserif", 1, 14));
        Daily_OtherServices.setText("Services");

        Daily_TerminalTotal.setFont(new java.awt.Font("sansserif", 1, 14));
        Daily_TerminalTotal.setText("Total: PHP");

        jLabel1.setFont(new java.awt.Font("sansserif", 1, 14));
        jLabel1.setText("Total: PHP");

        jLabel2.setFont(new java.awt.Font("sansserif", 1, 18));
        jLabel2.setText("Total Income:");

        jTextField3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jTextField3ActionPerformed(evt);
            }
        });

        ServiceTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Name/Terminal #", "Service", "Price"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.String.class, java.lang.Float.class
            };
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(ServiceTable);

        jButton1.setText("Generate Text File");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout DailyPanelLayout = new javax.swing.GroupLayout(DailyPanel);
        DailyPanel.setLayout(DailyPanelLayout);
        DailyPanelLayout.setHorizontalGroup(
            DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DailyPanelLayout.createSequentialGroup()
                .addGap(128, 128, 128)
                .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(DailyPanelLayout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(Daily_TerminalRentals))
                    .addComponent(Daily_Date))
                .addContainerGap(615, Short.MAX_VALUE))
            .addGroup(DailyPanelLayout.createSequentialGroup()
                .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(DailyPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1)
                        .addGap(268, 268, 268)
                        .addComponent(Daily_TerminalTotal)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(TerminalTotalText, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, DailyPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(Daily_TerminalRentalPannel, javax.swing.GroupLayout.PREFERRED_SIZE, 521, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(DailyPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 401, Short.MAX_VALUE)
                            .addComponent(Daily_OtherServices)))
                    .addGroup(DailyPanelLayout.createSequentialGroup()
                        .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, DailyPanelLayout.createSequentialGroup()
                                .addGap(166, 166, 166)
                                .addComponent(jLabel2)
                                .addGap(18, 18, 18)
                                .addComponent(TotalText, javax.swing.GroupLayout.PREFERRED_SIZE, 71, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(DailyPanelLayout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(ServiceTotalText, javax.swing.GroupLayout.PREFERRED_SIZE, 55, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(32, 32, 32)))
                .addGap(0, 0, 0))
            .addGroup(DailyPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(Daily_Day)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(DaySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Daily_Month)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(MonthCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Daily_Year)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(645, Short.MAX_VALUE))
        );
        DailyPanelLayout.setVerticalGroup(
            DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(DailyPanelLayout.createSequentialGroup()
                .addComponent(Daily_Date)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Daily_Day)
                    .addComponent(DaySpinner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Daily_Month)
                    .addComponent(MonthCombo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(Daily_Year)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Daily_TerminalRentals)
                    .addComponent(Daily_OtherServices))
                .addGap(18, 18, 18)
                .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Daily_TerminalRentalPannel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(DailyPanelLayout.createSequentialGroup()
                        .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(TerminalTotalText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(Daily_TerminalTotal))
                            .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(ServiceTotalText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(DailyPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(TotalText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel2)))
                    .addComponent(jButton1))
                .addContainerGap(118, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(Separator1, javax.swing.GroupLayout.DEFAULT_SIZE, 938, Short.MAX_VALUE)
                    .addComponent(Separator2, javax.swing.GroupLayout.DEFAULT_SIZE, 938, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(375, 375, 375)
                        .addComponent(ViewIncomeLabel))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addComponent(DailyButton)
                        .addGap(6, 6, 6)
                        .addComponent(WeeklyButton)
                        .addGap(6, 6, 6)
                        .addComponent(MonthlyButton)
                        .addGap(6, 6, 6)
                        .addComponent(YearlyButton))
                    .addComponent(DailyPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ViewIncomeLabel)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Separator1, javax.swing.GroupLayout.PREFERRED_SIZE, 2, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(DailyButton)
                    .addComponent(WeeklyButton)
                    .addComponent(MonthlyButton)
                    .addComponent(YearlyButton))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Separator2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(2, 2, 2)
                .addComponent(DailyPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void WeeklyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_WeeklyButtonActionPerformed
// TODO add your handling code here:
    terminalprice=0;
    serviceprice=0;
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
     while(terminaltable.getRowCount()!=0){
           terminaltable.removeRow(0);
       }
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM terminalrental");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String num=allTerminals.getString("RentalType");
           int TerminalNum=allTerminals.getInt("TerminalNumber");
           String start=allTerminals.getString("StartTime");
           String end=allTerminals.getString("EndTime");
           String duration=allTerminals.getString("Duration");
           float price=allTerminals.getFloat("TotalPrice");
           int day=allTerminals.getInt("day");
           int month=allTerminals.getInt("month");
           int year=allTerminals.getInt("year");
           
           Calendar cal = new GregorianCalendar(year, month, day);
           int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);  
           day=day-dayOfWeek;
           if((Integer)DaySpinner.getValue()>day && (Integer)DaySpinner.getValue()<=(day+8) && Integer.parseInt(jTextField3.getText())==year && (MonthCombo.getSelectedIndex()+1)==month)
           terminaltable.addRow(new Object[]{num,TerminalNum,start,end,duration,price});
           terminalprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
   while(servicetable.getRowCount()!=0){
           servicetable.removeRow(0);
       }
   
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM customer");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String name=allTerminals.getString("CustomerName");
           String serviceName=allTerminals.getString("ServiceName");
           float price=allTerminals.getFloat("ServiceTotal");
            int day=allTerminals.getInt("Day");
           int month=allTerminals.getInt("Month");
           int year=allTerminals.getInt("Year");
           Calendar cal = new GregorianCalendar(year, month, day);
           int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);  
           day=day-dayOfWeek;
           if((Integer)DaySpinner.getValue()>day && (Integer)DaySpinner.getValue()<=(day+8) && Integer.parseInt(jTextField3.getText())==year && (MonthCombo.getSelectedIndex()+1)==month)
           servicetable.addRow(new Object[]{name,serviceName,price});
           serviceprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
}//GEN-LAST:event_WeeklyButtonActionPerformed

private void DailyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DailyButtonActionPerformed
    terminalprice=0;
    serviceprice=0;
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
    while(terminaltable.getRowCount()!=0){
           terminaltable.removeRow(0);
       }
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM terminalrental");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String num=allTerminals.getString("RentalType");
           int TerminalNum=allTerminals.getInt("TerminalNumber");
           String start=allTerminals.getString("StartTime");
           String end=allTerminals.getString("EndTime");
           String duration=allTerminals.getString("Duration");
           float price=allTerminals.getFloat("TotalPrice");
           int day=allTerminals.getInt("day");
           int month=allTerminals.getInt("month");
           int year=allTerminals.getInt("year");
           if((Integer)DaySpinner.getValue()==day&& Integer.parseInt(jTextField3.getText())==year && (MonthCombo.getSelectedIndex()+1)==month)
           terminaltable.addRow(new Object[]{num,TerminalNum,start,end,duration,price});
           terminalprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
   while(servicetable.getRowCount()!=0){
           servicetable.removeRow(0);
       }
   
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM customer");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String name=allTerminals.getString("CustomerName");
           String serviceName=allTerminals.getString("ServiceName");
           float price=allTerminals.getFloat("ServiceTotal");
            int day=allTerminals.getInt("Day");
           int month=allTerminals.getInt("Month");
           int year=allTerminals.getInt("Year");
           if((Integer)DaySpinner.getValue()==day&& Integer.parseInt(jTextField3.getText())==year && (MonthCombo.getSelectedIndex()+1)==month)
           servicetable.addRow(new Object[]{name,serviceName,price});
           serviceprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
}//GEN-LAST:event_DailyButtonActionPerformed

private void jTextField3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField3ActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jTextField3ActionPerformed

private void YearlyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_YearlyButtonActionPerformed
// TODO add your handling code here:
    terminalprice=0;
    serviceprice=0;
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
    while(terminaltable.getRowCount()!=0){
           terminaltable.removeRow(0);
       }
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM terminalrental");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String num=allTerminals.getString("RentalType");
           int TerminalNum=allTerminals.getInt("TerminalNumber");
           String start=allTerminals.getString("StartTime");
           String end=allTerminals.getString("EndTime");
           String duration=allTerminals.getString("Duration");
           float price=allTerminals.getFloat("TotalPrice");
           int day=allTerminals.getInt("day");
           int month=allTerminals.getInt("month");
           int year=allTerminals.getInt("year");
           if(Integer.parseInt(jTextField3.getText())==year)
           terminaltable.addRow(new Object[]{num,TerminalNum,start,end,duration,price});
           terminalprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
   while(servicetable.getRowCount()!=0){
           servicetable.removeRow(0);
       }
   
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM customer");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String name=allTerminals.getString("CustomerName");
           String serviceName=allTerminals.getString("ServiceName");
           float price=allTerminals.getFloat("ServiceTotal");
            int day=allTerminals.getInt("Day");
           int month=allTerminals.getInt("Month");
           int year=allTerminals.getInt("Year");
           if(Integer.parseInt(jTextField3.getText())==year)
           servicetable.addRow(new Object[]{name,serviceName,price});
           serviceprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
}//GEN-LAST:event_YearlyButtonActionPerformed

private void MonthlyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MonthlyButtonActionPerformed
// TODO add your handling code here:
    terminalprice=0;
    serviceprice=0;
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
    while(terminaltable.getRowCount()!=0){
           terminaltable.removeRow(0);
       }
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM terminalrental");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String num=allTerminals.getString("RentalType");
           int TerminalNum=allTerminals.getInt("TerminalNumber");
           String start=allTerminals.getString("StartTime");
           String end=allTerminals.getString("EndTime");
           String duration=allTerminals.getString("Duration");
           float price=allTerminals.getFloat("TotalPrice");
           int day=allTerminals.getInt("day");
           int month=allTerminals.getInt("month");
           int year=allTerminals.getInt("year");
           if( Integer.parseInt(jTextField3.getText())==year && (MonthCombo.getSelectedIndex()+1)==month)
           terminaltable.addRow(new Object[]{num,TerminalNum,start,end,duration,price});
           terminalprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
   while(servicetable.getRowCount()!=0){
           servicetable.removeRow(0);
       }
   
    try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM customer");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String name=allTerminals.getString("CustomerName");
           String serviceName=allTerminals.getString("ServiceName");
           float price=allTerminals.getFloat("ServiceTotal");
            int day=allTerminals.getInt("Day");
           int month=allTerminals.getInt("Month");
           int year=allTerminals.getInt("Year");
           if(Integer.parseInt(jTextField3.getText())==year && (MonthCombo.getSelectedIndex()+1)==month)
           servicetable.addRow(new Object[]{name,serviceName,price});
           serviceprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
    TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
}//GEN-LAST:event_MonthlyButtonActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  try { 
      terminalprice=0;
        serviceprice=0;
          FileWriter outFile = new FileWriter("Income.txt");
             PrintWriter out = new PrintWriter(outFile);
                
                out.println("-=# Financial Report #=-");
               
                out.println(" ");
               
                out.println("# Terminal Rental #");
                for(int x=0;x<terminaltable.getRowCount();x++){
                String rental=(String)terminaltable.getValueAt(x,0);
                int num=(Integer)terminaltable.getValueAt(x,1);
                String start=(String)terminaltable.getValueAt(x,2);
                String end=(String)terminaltable.getValueAt(x,3);
                String time=(String)terminaltable.getValueAt(x,4);
                float price=(Float)terminaltable.getValueAt(x,5);
                out.println(rental+" | "+num+" | "+start+" | "+end+" | "+time+" | "+price);
                }
                out.println(" ");
                out.println("Rental Total Amount: "+TerminalTotalText.getText());
                out.println(" ");
                out.println("# Services #");
                for(int x=0;x<servicetable.getRowCount();x++){
                String name=(String)servicetable.getValueAt(x,0);
                String service=(String)servicetable.getValueAt(x,1);
                float price=(Float)servicetable.getValueAt(x,2);
                out.println(name+" | "+service+" | "+price);
                }
                
                out.println(" ");
                out.println("Individual Services");
                 DefaultTableModel countPerService = servicetable;
                while(countPerService.getRowCount()!=0){
                String name=(String)countPerService.getValueAt(0,1);
                int number=0;
                float total=0;
                for(int y=0;y<countPerService.getRowCount();y++){
                    String compare= (String)countPerService.getValueAt(y,1);
                    float amount= (Float)countPerService.getValueAt(y,2);
                  if(compare.equals(name)){
                      number++;
                      total+=amount;
                  }   
                }
                for(int z=0;z<number;z++){
                for(int y=0;y<countPerService.getRowCount();y++){
                    String compare= (String)countPerService.getValueAt(y,1);
                  if(compare.equals(name)){
                      countPerService.removeRow(y);
                  }   
                }
                }
                 out.println("-"+name+" | Total Number of Customer Availed: "+number+" | Total Amount: "+total);
                } 
                out.println(" ");
                out.println("Service Total Amount: "+ServiceTotalText.getText());
                out.println(" ");
                out.println("--------");
                out.println("Over All Total Amount: "+TotalText.getText());
                
                out.println(" ");
                
                 out.close();
                
}
         catch (IOException e){
             e.printStackTrace();
         }
  while(terminaltable.getRowCount()!=0){
           terminaltable.removeRow(0);
       }
   while(servicetable.getRowCount()!=0){
           servicetable.removeRow(0);
       }
  try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM terminalrental");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String num=allTerminals.getString("RentalType");
           int TerminalNum=allTerminals.getInt("TerminalNumber");
           String start=allTerminals.getString("StartTime");
           String end=allTerminals.getString("EndTime");
           String duration=allTerminals.getString("Duration");
           float price=allTerminals.getFloat("TotalPrice");
           terminaltable.addRow(new Object[]{num,TerminalNum,start,end,duration,price});
           terminalprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
          try{
        PreparedStatement pstmt= menu.con.prepareStatement("SELECT * FROM customer");
        ResultSet allTerminals= pstmt.executeQuery();
       while(allTerminals.next()){
           String name=allTerminals.getString("CustomerName");
           String serviceName=allTerminals.getString("ServiceName");
           float price=allTerminals.getFloat("ServiceTotal");
           servicetable.addRow(new Object[]{name,serviceName,price});
          serviceprice+=price;
        }
        }
        catch(SQLException ex){
            System.out.println("nada");
        } 
          
         TerminalTotalText.setText(Float.toString(terminalprice));
         ServiceTotalText.setText(Float.toString(serviceprice));
        TotalText.setText(Float.toString(terminalprice+serviceprice));
}//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        
        /* Create and display the form */
     
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton DailyButton;
    private javax.swing.JPanel DailyPanel;
    private javax.swing.JLabel Daily_Date;
    private javax.swing.JLabel Daily_Day;
    private javax.swing.JLabel Daily_Month;
    private javax.swing.JLabel Daily_OtherServices;
    private javax.swing.JScrollPane Daily_TerminalRentalPannel;
    private javax.swing.JLabel Daily_TerminalRentals;
    private javax.swing.JLabel Daily_TerminalTotal;
    private javax.swing.JLabel Daily_Year;
    private javax.swing.JSpinner DaySpinner;
    private javax.swing.JComboBox MonthCombo;
    private javax.swing.JButton MonthlyButton;
    private javax.swing.JSeparator Separator1;
    private javax.swing.JSeparator Separator2;
    private javax.swing.JTable ServiceTable;
    private javax.swing.JTextField ServiceTotalText;
    private javax.swing.JTable TerminalRentalTable;
    private javax.swing.JTextField TerminalTotalText;
    private javax.swing.JTextField TotalText;
    private javax.swing.JLabel ViewIncomeLabel;
    private javax.swing.JButton WeeklyButton;
    private javax.swing.JButton YearlyButton;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration//GEN-END:variables
}
